﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace HZY.Admin.Controllers.Sys
{
    using HZY.Toolkit;
    using HZY.Logic.Sys;
    using HZY.Models.Sys;
    using HZY.DTO;
    using HZY.DTO.Sys;

    public class RoleFunctionController : ApiBaseController
    {

        protected Sys_RoleMenuFunctionLogic logic { get; }
        protected Sys_RoleLogic roleLogic { get; }

        public RoleFunctionController(Sys_RoleMenuFunctionLogic _logic, Sys_RoleLogic _roleLogic)
        {
            this.logic = _logic;
            this.roleLogic = _roleLogic;
        }

        #region 基础 CURD

        /// <summary>
        /// 查询数据列表
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="Rows"></param>
        /// <param name="Search"></param>
        /// <returns></returns>
        [HttpPost("FindList/{Page}/{Rows}"),  ServiceFilter(typeof(Core.HZYApiAuthorizationCheckAttribute))]
        public async Task<ApiResult> FindListAsync(int Page, int Rows, [FromBody] Sys_Role Search)
        {
            var tableVM = await this.roleLogic.FindListAsync(Page, Rows, Search);
            return this.JsonOk(tableVM);
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        [HttpPost("Save"),  ServiceFilter(typeof(Core.HZYApiAuthorizationCheckAttribute))]
        public async Task<ApiResult> SaveAsync([FromBody]Sys_RoleMenuFunctionDto Model)
        {
            await this.logic.SaveAsync(Model);
            return this.JsonOk();
        }

        ///// <summary>
        ///// 删除数据
        ///// </summary>
        ///// <param name="idsDto"></param>
        ///// <returns></returns>
        //[HttpPost("Delete"), Core.HZYApiAuthorizationCheckFilter]
        //public async Task<ApiResult> DeleteAsync([FromBody]IdsDto<Guid> idsDto)
        //{
        //    await this.logic.DeleteAsync(idsDto);
        //    return this.JsonOk();
        //}

        ///// <summary>
        ///// 根据Id 加载表单数据
        ///// </summary>
        ///// <param name="Id"></param>
        ///// <returns></returns>
        //[HttpPost("LoadForm/{Id}"), Core.HZYApiAuthorizationCheckFilter]
        //public async Task<ApiResult> LoadFormAsync(Guid Id)
        //{
        //    await this.logic.LoadFormAsync(Id);
        //    return this.JsonOk();
        //}

        #endregion

        #region 其他

        /// <summary>
        /// 获取菜单功能树
        /// </summary>
        /// <returns></returns>
        [HttpPost("RoleMenuFunctionTree/{RoleId}"),  ServiceFilter(typeof(Core.HZYApiAuthorizationCheckAttribute))]
        public async Task<ApiResult> RoleMenuFunctionTree(Guid RoleId)
        {
            var tuple = await this.logic.GetRoleMenuFunctionTreeAsync(RoleId);

            return this.JsonOk(new
            {
                expandedRowKeys = tuple.Item1,
                list = tuple.Item2
            });
        }

        #endregion



    }
}